<?php

namespace app\admin\controller;
use think\Db;
use think\Controller;
use think\Request;
use think\Session;


class Comment extends AdminController
{
    public function _initialize(){
        parent::_initialize();
    }

    public function index()
    {
        // 读取评论列表
        $data =Db::table('sm_h_user')
                ->alias('shu')
                ->join('sm_h_comment shc', 'shu.id  = shc.uid')
                ->join('sm_h_movie shm', 'shm.id = shc.mid')
                ->field('shu.id,shu.name,shm.id,shm.mname,shm.type,shc.comment,shc.id,shc.score')
                ->paginate(8);
        $page = $data->render();
        return view('admin@Comment/index',[
            'data' => $data,
            'title' => '显示评论',
            'page' => $page,
        ]);
    }

    public function search()
    {
        $where = [];
        $keyword  = isset($_GET['keyword'])?$_GET['keyword'] : '';
        if($keyword){
            $where['comment'] = ['like', '%'.$keyword.'%'];
         
         // var_dump($list);die;
             $data =Db::table('sm_h_user')
                ->alias('shu')
                ->join('sm_h_comment shc', 'shu.id  = shc.uid')
                ->join('sm_h_movie shm', 'shm.id = shc.mid')
                ->field('shu.id,shu.name,shm.id,shm.mname,shm.type,shc.comment,shc.score,shm.type,shc.id')
                ->where($where)
                ->select();
       if ($data) {
           return view('admin@Comment/search',[
                'title' => '搜索评论关键字:'.$keyword,
                // 'list' => $list,
                'data' => $data,
            ]);
       }else{
        return view('admin@Comment/search',[
                'title' => '搜索评论关键字:'.$keyword,
                'res' => '没有找到关于 ['.$keyword.'] 的评论，换个搜索词试试吧。',
            ]);
       }

         
     }else{
         return view('admin@Comment/search',[
                'title' => '搜索评论关键字:'.$keyword,
                'res' => '没有找到关于 [ ] 的评论，换个搜索词试试吧。',
            ]);
     }
    }

    public function delete($id)
    {
//         echo $id;
        $result = db('h_comment')->delete($id);
        if ($result > 0) {
            $info['status'] = true;
        } else {
            $info['status'] = false;
        }
        return json($info);

    }


    
}